package com.testingedu.action.background;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSON;
import net.sf.json.JSONArray;

import com.testingedu.jdbcDao.TMenuDao;
import com.testingedu.json.ZTreeNode;
import com.testingedu.model.TMenu;

public class TMenuAction extends RequestContext {
	private static final long serialVersionUID = 2265152031568341652L;
	private static TMenuDao tMenuDao = new TMenuDao();
	
	public void _leftMenuList() throws Exception {
		int userId = getTUserId();
		String menuId = request.getParameter("id");
		if(menuId == null || menuId.trim().length() == 0) {
			menuId = "1";
		}
		List<TMenu> tMenus = tMenuDao.leftMenuList(userId, Integer.parseInt(menuId));
		List<ZTreeNode> nodes = new ArrayList<ZTreeNode>();
		for (TMenu m : tMenus) {
			if(tMenuDao.hasChildren(m.getId())) {
				nodes.add(new ZTreeNode(m.getId(), m.getName(), menuId,
						"true", true));
			} else {
				nodes.add(new ZTreeNode(m.getId(), m.getName(), menuId, m
						.getUrl(), "right", "true"));
			}
		}
		JSON json = JSONArray.fromObject(nodes);
		PrintWriter writer = response.getWriter();
		writer.write("刘世伟");
		writer.close();
	}
}
